import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:wallet_utils/color.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wallet_utils/report_widget/click_widget.dart';
import 'package:wallet_utils/text_style.dart';
import 'package:wallet_utils/toast.dart';
import 'package:wallet_utils/webview_common.dart';
import 'package:get/get.dart';

/**
 * @author kxc on 2023/2/27
 * @description
 */
class GeneralDialog extends StatefulWidget {
  final VoidCallback? checkCallback;
  num? amount;
  String? name;
  String? popLinkUrl;
  final VoidCallback? h5Callback;
  String? agreementName;
  String? agreementContent;

  GeneralDialog({
    Key? key,
    this.checkCallback,
    this.amount,
    this.name,
    this.agreementName,
    this.agreementContent,
    this.popLinkUrl,
    this.h5Callback,
  }) : super(key: key);

  @override
  _GeneralDialogState createState() => _GeneralDialogState();
  bool isAgreeUserPrivary = false;

  void showGeneralFunction(context) {
    showGeneralDialog(
      context: context,
      barrierLabel: "",
      barrierDismissible: false,
      barrierColor: Colors.black.withOpacity(.5),
      transitionDuration: Duration(milliseconds: 300),
      transitionBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
        return FractionalTranslation(
          //从左向右滑出
          // translation: Offset(animation.value - 1, 0),
          //从右向左滑出
          // translation: Offset(1 - animation.value, 0),
          //从顶部滑出
          translation: Offset(0, animation.value - 1.39),
          //从底部滑出
          // translation: Offset(0, 1 - animation.value),
          child: child,
        );
      },
      pageBuilder: (BuildContext context, Animation animation, Animation secondaryAnimation) {
        return GeneralDialog(
          amount: amount,
          name: name,
          agreementName: agreementName,
          agreementContent: agreementContent,
          popLinkUrl: popLinkUrl,
          h5Callback: h5Callback,
        );
      },
    );
  }
}

class _GeneralDialogState extends State<GeneralDialog> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Material(
        color: ColorManager.Transparent,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              width: double.infinity,
              height: 750.w + ScreenUtil().statusBarHeight,
              alignment: Alignment.center,
              decoration: const BoxDecoration(
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(10.0),
                    bottomRight: Radius.circular(10.0),
                  ),
                  color: Colors.white),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    margin: EdgeInsets.only(top: ScreenUtil().statusBarHeight + 300.w),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: EdgeInsets.only(left: 15.w),
                    child: Image.asset(
                      'images/auth_reco_logo.png',
                      width: 44.w,
                      height: 10.w,
                    ),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Image.asset(
                        'images/icon_complete.png',
                        width: 20.w,
                        height: 20.w,
                      ),
                      SizedBox(
                        width: 10.w,
                      ),
                      Text(
                        '恭喜您，已通过初审',
                        style: TextStyleUtils.style000000(fontSize: 16.sp, fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                  Container(
                    height: 105.w,
                    width: double.infinity,
                    margin: EdgeInsets.only(left: 16.w, right: 16.w,  bottom: 10.w),
                    decoration: BoxDecoration(
                      color: ColorManager.colorFFFFFF,
                      //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                      borderRadius: BorderRadius.all(Radius.circular(5.0)),
                    ),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '${widget.amount}元',
                          style: TextStyleUtils.styleFFECE9(fontSize: 32.sp, fontWeight: FontWeight.bold),
                        ),
                        Text(
                          '您的借款将由合作方${widget.name}提供',
                          style: TextStyleUtils.style666666(fontSize: 12.sp),
                        )
                      ],
                    ),
                  ),
                  Container(
                    width: double.infinity,
                    alignment: Alignment.center,
                    margin: EdgeInsets.only(left: 15.w, right: 15.w,bottom: 15.w,),
                    padding: EdgeInsets.only(left: 8.w, right: 8.w,bottom: 10.w),
                    decoration: BoxDecoration(
                      color: ColorManager.colorFFF7F2,
                      //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                      borderRadius: BorderRadius.all(Radius.circular(5.0)),
                    ),
                    height: 130.w,
                    child: MediaQuery.removePadding(
                      removeTop: true,
                      context: context,
                      child: ListView(
                        shrinkWrap: true,
                        children: [
                          Text(
                            widget.agreementName ?? '',
                            style: TextStyle(fontSize: 14.sp, color: ColorManager.color000000, fontWeight: FontWeight.w600),
                            textAlign: TextAlign.center,
                          ),
                          HtmlWidget(
                            widget.agreementContent ?? '',
                            textStyle: TextStyleUtils.style000000(fontSize: 13.sp),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: 22.w,
                    padding: EdgeInsets.only(left: 8.w, right: 8.w, top: 3.w),
                    decoration: BoxDecoration(
                      color: ColorManager.colorFFD5A6,
                      //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                      borderRadius: BorderRadius.all(Radius.circular(20.0)),
                    ),
                    child: Text(
                      '24小时内申请提现成功率最高，赶快去提现吧',
                      style: TextStyleUtils.styleB45602(fontSize: 10.sp),
                    ),
                  ),
                  ClickWidget(
                    onTap: () {
                      if (widget.amount != null && widget.name != null) {
                          Get.to(WebViewCommon(
                            widget.popLinkUrl ?? '',
                          ));
                      }
                    },
                    child: Container(
                      width: double.infinity,
                      height: 48.w,
                      alignment: const Alignment(0, 0),
                      margin: EdgeInsets.only(right: 16.w, left: 16.w, top: 7.w),
                      decoration: BoxDecoration(
                        color: ColorManager.colorD93C3A,
                        //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                        borderRadius: BorderRadius.all(Radius.circular(25.0)),
                      ),
                      child: Text(
                        '同意协议并申请',
                        style: TextStyleUtils.styleFFFFFF(fontSize: 16.sp, fontWeight: FontWeight.bold),
                      ),
                    ),
                  ),

                ],
              ),
            ),
            Container(
              height: 12.w,
            ),
            ClickWidget(
              onTap: () {
                Get.back();
              },
              child: Image.asset(
                'images/home_alert_close.png',
                width: 20.w,
                height: 20.w,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
